#include "Include.h"

vu16 Beep_Cnt;
vu8 Beep_Cmd;

void Beep_Init()
{
    BEEP_OFF();	
}

void Beep_Task() // 20ms
{
    static vu8 Beep_Off_Cnt = 0;

    switch (Beep_Cmd)
    {
    case 0:

        break;
    //--------------------------
    case 1: // 1 beep 200ms
    	//------------------------
		#if BUZZER_IO_TYPE == 1	
       		Beep_Cnt = 10;  // 20ms*10 PCK
    	#else
        	Beep_Cnt = 200;	//20ms*10 IO
        #endif
   		//------------------------
        Beep_Cmd = 0;
		
        break;
    //--------------------------
    case 2: // 2 beep
    	//------------------------
        #if BUZZER_IO_TYPE == 1	
       		Beep_Cnt = 10;  // 20ms*10 pck
    	#else
        	Beep_Cnt = 200;	//20ms*10 IO
        #endif
        //------------------------       
        bBeep_State = 1;
        Beep_Cmd = 0;
      
        break;
    //--------------------------
    case 3: // 1 beep 1s
		//--------------------------
		#if BUZZER_IO_TYPE == 1	
       		Beep_Cnt = 50; 	// 20ms*50 PCK
    	#else
        	Beep_Cnt = 1000;	//20ms*10 IO
        #endif
  		//--------------------------
        Beep_Cmd = 0;
     
        break;
    //--------------------------
    default:
        break;
    }

    if (Beep_Cnt != 0)
    {
    	#if BUZZER_IO_TYPE == 1	//PCK
    		Beep_Cnt--;
			BEEP_ON();
    	#endif
        bBeep_ON = 1;
    }
    else
    {
    	#if BUZZER_IO_TYPE == 1	//PCK
    		BEEP_OFF();
    	#endif
    	
	    if (1 == bBeep_State)
	    {
	        if (++Beep_Off_Cnt > 25) //
	        {
	            bBeep_State = 0;
	            Beep_Off_Cnt = 0;
	            Beep_Cmd = 1;
	        }
	    }
  	}
}	

void Fan_Task()
{
	if (1 == ControlSet_App.flagBit.fan)
	{
	    //FAN_ON();
	    //_pwm1en1=0; _pwm1en0=1;//disable PWM output high
	    _pc0=ON;
	}
	else
	{
		//FAN_OFF();
		//_pwm1en1=0; _pwm1en0=0;//disable PWM output low
		_pc0=OFF;
	}	
}